//引入jwt
const jwt = require('jsonwebtoken');
var express_jwt = require('express-jwt');

//创建jwt
let createJwt = (payload)=>jwt.sign(payload,"f77codejwt123456",{expiresIn:24*60});

//验证Jwt 的方法
let authJwt = express_jwt({
    secret:'f77codejwt123456', //密钥
    algorithms: ['HS256'], //加密的方法
    credentialsRequired: false, // 是否对jwt进行验证 false：不验证， true:需要验证
    }).unless({path: ['/admins/login'] //哪些路径不进行验证
})

//验证(解密)
 let decoded = function(data){
      return jwt.verify(data,'f77codejwt123456'); 
     }
     //这里面还需要传入签名也就是密钥

// console.log(decoded.username) 

module.exports = {createJwt,authJwt,decoded}
